package chapter15.exercise;

import java.util.ArrayList;
import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
import java.util.Queue;
import java.util.Set;

import com.common.utils.Generator;

public class Generators {
    public static <T> Collection<T> fill(Collection<T> coll, Generator<T> gen, int n) {
        for (int i = 0; i < n; i++)
            coll.add(gen.next());
        return coll;
    }

    public static <T> List<T> fill(List<T> list, Generator<T> gen, int n) {
        for (int i = 0; i < n; i++)
            list.add(gen.next());
        return list;
    }

    public static <T> LinkedList<T> fill(LinkedList<T> list, Generator<T> gen, int n) {
        for (int i = 0; i < n; i++)


            list.add(gen.next());
        return list;
    }

    public static <T> Set<T> fill(Set<T> set, Generator<T> gen, int n) {
        for (int i = 0; i < n; i++)
            set.add(gen.next());
        return set;
    }

    public static <T> Queue<T> fill(Queue<T> queue, Generator<T> gen, int n) {
        for (int i = 0; i < n; i++)
            queue.add(gen.next());
        return queue;
    }

    public static void main(String[] args) {
        Collection<Coffee> coff = fill(new ArrayList<Coffee>(), new CoffeeGenerator(), 5);
        for (Coffee coffee : coff) {
            System.out.println(coffee);
        }
        Collection<Integer> inte = fill(new ArrayList<Integer>(), new Fibonacci(), 18);
        for (Integer integer : inte) {
            System.out.print(integer + " ");
        }
    }
}
